package com.authine.cloudpivot.ext.controller;

import com.authine.cloudpivot.engine.api.model.runtime.AttachmentModel;
import com.authine.cloudpivot.engine.api.model.runtime.BizObjectCreatedModel;
import com.authine.cloudpivot.web.api.controller.base.BaseController;
import com.authine.cloudpivot.web.api.view.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author hxd
 * @Date 2022/1/18 16:36
 * @Description
 **/
@RestController
@RequestMapping("/public")
@Slf4j
public class TzyhController extends BaseController {

    @GetMapping(value = "/getUser")
    public Map<String,Object> getUser(@RequestParam Integer id){
        Map<String,Object> data = new HashMap<>();
        data.put("id",id);
        data.put("userName","admin");
        data.put("from","provider-A");
        return data;
    }


    @GetMapping("/startOaWrokflow")
    public ResponseResult startOaWrokflow(@RequestParam String bizId,@RequestParam String refId){

        AttachmentModel attachment = getBizObjectFacade().getAttachmentByRefId(refId);

        if (attachment == null) {
            log.info("============附件不存在,refId={}",refId);
            return getErrResponseResult(-1l,"附件不存在");
        }

        BizObjectCreatedModel bizObject = getBizObjectFacade().getBizObject("", bizId);



        if (bizObject == null) {
            log.info("=============流程数据不存在,bizId={}",bizId);
            return getErrResponseResult(-1l,"流程数据不存在");
        }

        //获取附件byte

        //上传附件三方系统 ,返回相关信息并保存


        getBizObjectFacade().saveBizObject(getUserId(), bizObject, false);

        //启动oa流程


        return getOkResponseResult("成功");


    }

}
